/*
 * Copyright (C) 2011 ViewlinkDC++ Team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef _UPDATE_DLG_H_
#define _UPDATE_DLG_H_

#pragma once


#include "Resource.h"
#include <string>
using namespace std;

class UpdateDlg
{
public:
	enum { IDD = IDD_VIEWUPDATE };
	UpdateDlg(wstring const& viewFolder, wstring const& updateFolder, wstring const& stageID, BOOL isDeleteMode = FALSE, BOOL isFinalTry = FALSE) 
		: _stageID(stageID)
		, _viewFolder(viewFolder)
		, _updateFolder(updateFolder)
		, _updateThread(NULL)
		, _isDeleteMode(isDeleteMode)
		, _error(0) 
		, _isFinalTry(isFinalTry)
	{}
	~UpdateDlg(void);
	//BEGIN_MSG_MAP(MagnetDlg)
	//	MESSAGE_HANDLER(WM_INITDIALOG, onInitDialog)
	//	COMMAND_ID_HANDLER(IDCANCEL, onCloseCmd)
	//END_MSG_MAP();

	LRESULT onInitDialog(HWND hDlg);
	LRESULT onCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

	LRESULT DoModal(HWND parent);

	DWORD GetError() { return _error; }

private:
	wstring _stageID;
	wstring _viewFolder;
	wstring _updateFolder;
	HANDLE _updateThread;
	bool   _isCancel;
	BOOL _isDeleteMode;
	BOOL _isFinalTry;
	HWND _hDlg;

	// CProgressBarCtrl progress;
private:
	static UpdateDlg* _currentInstance;


private:
	UpdateDlg() { }
	static INT_PTR CALLBACK ViewUpdateDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

protected:
	static DWORD WINAPI UpdateDialogProc( LPVOID lpParam );
	void updateProcFailed();
	void updateProcSuccess();
	void SetProgressPos(int iPos, int iMaxPos, LPCTSTR stagePosLabel = NULL, LPCTSTR stageLabel = NULL);
	DWORD _error;
};

#endif // _UPDATE_DLG_H_